/*
 * create an instance of GameCanvas in your main game
 */
package engine;

import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;

public class GameCanvas extends Canvas{
	
	private GameBase game;
	private BufferedImage bufferData;
	private Graphics buffer;
	
	
	public GameCanvas(GameBase gm, int width, int height){
		setPreferredSize(new Dimension(width, height));
		game = gm;
	}
	
	public void paint(Graphics screen){
		
		if (bufferData == null)
		{
			bufferData = (BufferedImage)createImage(getWidth(), getHeight());
			buffer = bufferData.getGraphics();
		}
		
		game.draw(buffer);
		screen.drawImage(bufferData, 0, 0, null);
	}
	
	public void start(){
		
		while(true){
			this.repaint();
			game.update();
		}
	}
}
